#include <iostream>
#include <string>
#include <regex>

int main()
{



    //-------------------解析请求头
    //这是一个标准的http请求头
    std::string str{"GET /user/getInfo?username=nhy&password=123 HTTP/1.1\n"};
    std::regex re{"(GET|PUT|DELETE|POST|HEAD) ([^?]*)(?:\\?(.*))? (HTTP/1\\.[01])(?:\n|\r\n)?"};
    std::smatch matches;

    int ret = std::regex_match(str, matches, re);
    if(!ret){
        std::cout << "匹配失败" << std::endl;
    }else {
        std::cout << "匹配成功" << std::endl;  
        for(auto s : matches){
            std::cout << s << std::endl;
        }
    }
    //-------------------测试正则
    // std::string str("/nums/1234");
    // std::regex re("/nums/(\\d+)");
    // std::smatch sm;
    
    // int ret = std::regex_match(str, sm, re);
    // if(!ret){
    //     std::cout << "匹配失败" << std::endl;
    // }else {
    //     std::cout << "匹配成功" << std::endl;  
    //     for(auto it : sm){
    //         std::cout << it << std::endl;
    //     }
    // }
}